package com.sxbbc.plat.controller.jz;

import java.util.Date;

import javax.servlet.http.HttpServletResponse;

import com.sxbbc.common.core.entity.jz.*;
import com.sxbbc.common.core.service.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sxbbc.common.basics.utils.date.DateUtil;
import com.sxbbc.common.basics.utils.export.ExportUtil;
import com.sxbbc.common.basics.utils.statics.StaticUtils;
import com.sxbbc.common.core.utils.BasePage;
import com.sxbbc.plat.common.ExportMapping;
import com.sxbbc.plat.service.ExportService;

/**
 * 导出操作 控制层
 *
 * @author leehao
 * @date 2019-05-07 17:27
 */
@Controller
public class ExportController {

    @Autowired
    private ExportService exportService;
    @Autowired
    private ICMoneyDetailService moneyDetailsService;
    @Autowired
    private ICPointDetailService pointDetailsService;
    @Autowired
    private ICDonateDetailService donateDetailsService;
    @Autowired
    private ICShareDetailService shareDetailsService;
    @Autowired
    private IOrderMainService orderMainService;
    @Autowired
    private IAgDonateDetailService agDonateDetailService;

    /**
     * 导出会员金额明细信息
     * @author leehao
     */
    @RequestMapping(value = ExportMapping.HANDLE_EXPORT_CUSTOMER_MONEY)
    public void handleExportCusMoneyDetail(HttpServletResponse response,BasePage<CMoneyDetail> page,
                                           CMoneyDetail detail){
        page.setSize(StaticUtils.EXCEL_MAX_LINE);
        moneyDetailsService.queryCustomerMoneyList(page, detail);
        HSSFWorkbook wb = exportService.exportCustomerMoney(page.getRecords());
        ExportUtil export = ExportUtil.getInstance();
        String fileName = "会员金额明细列表_" + DateUtil.getInstance().toDateString(new Date()) + ".xls";
        export.exportFiles(response,fileName,wb);
    }

    /**
     * 导出会员积分明细信息
     * @author leehao
     */
    @RequestMapping(value = ExportMapping.HANDLE_EXPORT_CUSTOMER_POINT)
    public void handleCusPointDetail(HttpServletResponse response, BasePage<CPointDetail> page,
                                     CPointDetail details){
        page.setSize(StaticUtils.EXCEL_MAX_LINE);
        IPage<CPointDetail> list = pointDetailsService.queryCustomerPointList(page, details);
        HSSFWorkbook wb = exportService.exportCustomerPoint(list.getRecords());
        ExportUtil export = ExportUtil.getInstance();
        String fileName = "会员积分明细列表_" + DateUtil.getInstance().toDateString(new Date()) + ".xls";
        export.exportFiles(response,fileName,wb);
    }
    
    /**
     * 导出会员贡献值明细信息
     * @author xiaoky
     */
    @RequestMapping(value = ExportMapping.HANDLE_EXPORT_CUSTOMER_DONATE)
    public void handleCusDonateDetail(HttpServletResponse response, BasePage<CDonateDetail> page,
    		CDonateDetail details){
        page.setSize(StaticUtils.EXCEL_MAX_LINE);
    	IPage<CDonateDetail> list = donateDetailsService.queryCustomerDonateList(page, details);
    	HSSFWorkbook wb = exportService.exportCustomerDonate(list.getRecords());
    	ExportUtil export = ExportUtil.getInstance();
    	String fileName = "会员贡献值明细列表_" + DateUtil.getInstance().toDateString(new Date()) + ".xls";
    	export.exportFiles(response,fileName,wb);
    }
    
    /**
     * 导出会员共享值明细信息
     * @author xiaoky
     */
    @RequestMapping(value = ExportMapping.HANDLE_EXPORT_CUSTOMER_SHARE)
    public void handleCusShareDetail(HttpServletResponse response, BasePage<CShareDetail> page,
    		CShareDetail details){
        page.setSize(StaticUtils.EXCEL_MAX_LINE);
    	IPage<CShareDetail> list = shareDetailsService.queryCustomerShareList(page, details);
    	HSSFWorkbook wb = exportService.exportCustomerShare(list.getRecords());
    	ExportUtil export = ExportUtil.getInstance();
    	String fileName = "会员共享值明细列表_" + DateUtil.getInstance().toDateString(new Date()) + ".xls";
    	export.exportFiles(response,fileName,wb);
    }
    
    /**
     * 导出订单数据
     * @param response
     * @param page 
     * @param order 订单
     */
    @RequestMapping(value = ExportMapping.HANDLE_EXPORT_ORDER)
    public void handleExportOrder(HttpServletResponse response, BasePage<OrderMain> page,
    		OrderMain order){
        page.setSize(StaticUtils.EXCEL_MAX_LINE);
    	// 查询未删除的订单
    	order.setDel(StaticUtils.STATUS_NO);
    	orderMainService.queryOrder(page, order);
    	HSSFWorkbook wb = exportService.exportOrder(page.getRecords());
    	ExportUtil export = ExportUtil.getInstance();
    	String fileName = "会员订单列表_" + DateUtil.getInstance().toDateString(new Date()) + ".xls";
    	export.exportFiles(response,fileName,wb);
    }


    @RequestMapping(value = ExportMapping.HANDLE_EXPORT_AGENT_DONATE)
    public void handleExportAgentDonateDetail(HttpServletResponse response, BasePage<AgDonateDetail> page,
    		AgDonateDetail agDonateDetail){
        page.setSize(StaticUtils.EXCEL_MAX_LINE);
        agDonateDetailService.queryAgentDonateDetail(page, agDonateDetail);
    	HSSFWorkbook wb = exportService.exportAgentDonate(page.getRecords());
    	ExportUtil export = ExportUtil.getInstance();
    	String fileName = "代理贡献值列表_" + DateUtil.getInstance().toDateString(new Date()) + ".xls";
    	export.exportFiles(response,fileName,wb);
    }
}
